/*
 * FILE								: i2c.h
 * DESCRIPTION				: This file is iHMI43 i2c file header.
 * Author							: XiaomaGee@Gmail.com
 * Copyright					:
 *
 * History
 * --------------------
 * Rev								:0.00
 * Date								:08/26/2012
 *
 * create.
 * --------------------
 */

//-------------------Define-----------------------------//
#ifndef __i2c_h__
#define __i2c_h__
#include "..\fwlib\inc\stm32f4xx_gpio.h"
//-----------------Include files-------------------------//

//------------------Define-------------------------------//
#define SCL_OUTPUT      GPIO_uInitStructure.GPIO_Pin = GPIO_Pin_8;\
		GPIO_uInitStructure.GPIO_Mode = GPIO_Mode_OUT;\
		GPIO_uInitStructure.GPIO_OType = GPIO_OType_PP;\
		GPIO_uInitStructure.GPIO_PuPd = GPIO_PuPd_UP;\
		GPIO_uInitStructure.GPIO_Speed = GPIO_Speed_100MHz;\
		GPIO_Init(GPIOD,&GPIO_uInitStructure)

#define SDA_OUTPUT      GPIO_uInitStructure.GPIO_Pin = GPIO_Pin_9;\
		GPIO_uInitStructure.GPIO_Mode = GPIO_Mode_OUT;\
		GPIO_uInitStructure.GPIO_OType = GPIO_OType_PP;\
		GPIO_uInitStructure.GPIO_PuPd = GPIO_PuPd_UP;\
		GPIO_uInitStructure.GPIO_Speed = GPIO_Speed_100MHz;\
		GPIO_Init(GPIOD,&GPIO_uInitStructure)

#define SDA_INPUT       GPIO_uInitStructure.GPIO_Pin = GPIO_Pin_9;\
		GPIO_uInitStructure.GPIO_Mode = GPIO_Mode_IN;\
		GPIO_uInitStructure.GPIO_Speed = GPIO_Speed_100MHz;\
		GPIO_uInitStructure.GPIO_PuPd = GPIO_PuPd_UP;\
		GPIO_Init(GPIOD, &GPIO_uInitStructure)

#define SCL_ON          GPIO_SetBits(GPIOD,GPIO_Pin_8)
#define SCL_OFF         GPIO_ResetBits(GPIOD,GPIO_Pin_8)

#define SDA_ON          GPIO_SetBits(GPIOD,GPIO_Pin_9)
#define SDA_OFF         GPIO_ResetBits(GPIOD,GPIO_Pin_9)

#define SDA_DATA        GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_9)
//----------------- Typedef------------------------------//
typedef  struct{
	int (* initialize)(void);
	unsigned char (* read)(void);
	int (* write)(unsigned char data);
	int (* start)(void);
	int (* stop)(void);
	int (* check_ack)(void);
	int (* ack)(char);
	int ack_flag;
	int (* read_nbyte)(unsigned char ,unsigned char,char *,unsigned char);
	int (* write_nbyte)(unsigned char ,unsigned char,char *,unsigned char);
	}MY_I2C_T;
//----------------- Extern ------------------------------//
extern MY_I2C_T i2c;
#endif //__i2c_h__
